async function handleLogin() {
    const username = document.getElementById('username').value;
    const password = document.getElementById('password').value;

    if (!username || !password) {
        alert('请填写完整信息');
        return;
    }

    try {
        const response = await API.user.login({
            uid: username,
            password: password
        });

        if (response && response.utype !== undefined) {
            localStorage.setItem('userInfo', JSON.stringify({
                uid: username,
                utype: response.utype
            }));
            
            switch(response.utype) {
                case 0:
                    window.location.href = 'admin/index.html';
                    break;
                case 1:
                    window.location.href = 'employee/index.html';
                    break;
                case 2:
                    window.location.href = 'user/index.html';
                    break;
                default:
                    alert('未知的用户类型');
                    break;
            }
        } else {
            alert('登录失败，用户名或密码错误');
        }
    } catch (error) {
        console.error('登录失败:', error);
        alert('登录失败：' + (error.message || '未知错误'));
    }
} 